<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="lib/react.development.js"></script>
    <script src="lib/react-dom.development.js"></script>
    <script src="lib/babel.min.js"></script>
</head>
<body>
    <div id="root"></div>
    <script type="text/babel">
    let {Component} = React

    class Demo extends Component{
        constructor(){
            super();
            this.state = {
                msg:'',
                arr:[]
            }
        }

        handleChecge = (ev)=>{
            this.setState({
                [ev.target.name]:ev.target.value
            })
           
        }
        handleSubmit = (ev)=>{
            
            let oldArr = [...this.state.arr];
            oldArr.push(this.state.msg)
            this.setState({
                arr:oldArr,
                msg:''
            })
            ev.preventDefault();
        }

        del = (index) =>{
            
            let arr = [...this.state.arr]
            arr.splice(index,1)
            this.setState({
                arr
            })

        }


        render(){
            return(
                <div>
                    <form onSubmit={this.handleSubmit}>
                        <input type="text" name="msg"  value={this.state.msg} onChange={this.handleChecge} />
                        <button>提交</button>
                    </form>
                    <ul>
                        {

                        this.state.arr.map((val,index)=>
                            <li key={index}>{val}<a href="javascript:;" onClick={()=>this.del(index)}>删除</a></li>
                        )
                        }
                    </ul>
                </div>
            )
        }
    }

    ReactDOM.render(
        <Demo />,
        document.querySelector("#root")
    )

    </script>
</body>
</html>